﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>企业-注册</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                var $btn = $(this).button('loading');
                var Company = new Object();
                Company.CompanyName = $("#CompanyName").val();
                Company.Email = $("#Email").val();
                Company.Password = $("#Password").val();
                Company.CompanyNumber = $("#CompanyNumber").val();
                if (Company.CompanyName == '' || Company.Email == '' || Company.Password == '' || Company.CompanyNumber =='')
                {
                    alert("公司名称或邮箱或工商注册号或密码不能为空！");
                    $btn.button('reset');
                    return false;
                }
                var file = $("#files").get(0);
                var files = file.files;
                var formdata = new FormData();
                if (files.length < 1)
                {
                    alert("请选择文件！");
                    $btn.button('reset');
                    return false;
                }
               for (var i = 0; i < files.length; i++) {
                 formdata.append("files", files[i]);
                }
                $.ajax({
            type: 'Post',
            data: formdata,
            contentType: false,
            processData: false,
            url: "/Upload/FormImg",
            success: function (result) {
                if (result.returnCode == '999') {
                    alert('提交失败,重新尝试提交');
                     $btn.button('reset');
                    return false;
                }
                else if (result.returnCode == '4040') {
                    alert('文件不是.gif|.jpg|.jpeg|.png结尾');
                     $btn.button('reset');
                    return false;
                }
                else if (result.returnCode == '4050') {
                    alert('文件大于2M');
                     $btn.button('reset');
                    return false;
                }
                else {
                    Company.BusinessLicense = result.returnCode;

                     $.ajax({
                    type: "post",
                    url: "/Company/CompanyRegister",
                    contentType: "application/json",
                    data: JSON.stringify(Company),
                    dataType: "json",
                    success: function (message) {
                        if (message.returnCode == "001") {
                             $btn.button('reset');
                            location.href = "/Company/CompanyLogin";
                        }
                        else if(message.returnCode == '900'){
                            alert("注册失败！公司名称重复");
                            $btn.button('reset');
                        }
                        else if(message.returnCode == '910'){
                            alert("注册失败！邮箱重复");
                            $btn.button('reset');
                        }
                         else if(message.returnCode == '920'){
                            alert("注册失败！工商注册号重复");
                            $btn.button('reset');
                        }
                    }
                });
                }
            }
        });
            });
        });
    </script>
</head>
<body style="background-image:url(/background-image/login-bg-autumn.jpg)">
    <div style="margin-top: 50px;">
        <div class="container">
            <div class="row clearfix">
                <div class="col-md-4 column">
                </div>
                <div class="col-md-4 column">
                    <form>
                        <div class="form-group">
                            <label>企业名称</label>
                            <input type="text" class="form-control" id="CompanyName" placeholder="请输入企业名称..." required />
                        </div>
                        <div class="form-group">
                            <label>邮箱</label>
                            <input type="email" class="form-control" id="Email" placeholder="请输入企业邮箱..." required autofocus />
                        </div>
                        <div class="form-group">
                            <label>工商注册号</label>
                            <input type="text" class="form-control" id="CompanyNumber" placeholder="请输入工商注册号..." required />
                        </div>
                        <div class="form-group">
                            <label>密码</label>
                            <input type="password" class="form-control" id="Password" placeholder="请输入密码..." required />
                        </div>
                        <div class="form-group">
                            <input type="file" id="files" value="选择需要上传的图片" accept=".jpg,.jpeg,.png" /><p style="color :red">支持.gif .jpg .jpeg .png文件</p>
                        </div>
                        <button type="button" id="register" class="btn btn-default btn-info btn-block" data-loading-text="注册中...">注册</button>
                        <a href="/Company/CompanyLogin" class="btn btn-default btn-warning btn-block">去登陆</a>
                    </form>
                </div>
                <div class="col-md-4 column">
                </div>
            </div>
        </div>
    </div>
</body>
</html>

